<?php
// +----------------------------------------------------------------------
// | FnuiSaas 天添客Saas框架
// +----------------------------------------------------------------------
// | Copyright (c) 2019-2021 中犇科技 All rights reserved.
// +----------------------------------------------------------------------
namespace app\api\controller\m2979;
use app\api\controller\Base;
use service\ApiReturn;
use think\helper\Hash;
use think\Db;
use app\member\model\Apilist as ApiLists;
use think\facade\Request;
use mypay\Payment;
/**
* 支付签名接口
* Class UserLabel
* @package app\api\controller\v1
*/
class PayApi extends Base
{

    /**
    * 获取微信开放平台预支付订单1
    * @param $data
    * @return mixed
    * @author 刘明美 [ liumingmei@zhongbenjituan.com ]
    */
    public function get_wxpay($data, $user) {
        $pay_config = Db::name("pay_config")->where("name", 0)->value("config");
        $pay_config = json_decode($pay_config, true);
        $arr = addons_action('WeChat', 'MiniPay', 'pay', [], $pay_config);
        p(123);
        //  $data["order_config_id"] = 13;
        //处理平台自己的订单
        $order_config_id = $data["order_config_id"];
        $order_config = Db::name("order_config")->where(["aid" => $order_config_id, "status" => 1])->find();
        $pay_config = Db::name("pay_config")->where("name", 0)->value("config");
        if (!$pay_config) {
            return ApiReturn::r(0, [], '微信支付配置不完善');
        } else {
            $pay_config = json_decode($pay_config, true);
        }
        if (!$order_config) {
            return ApiReturn::r(0, [], '订单配置不存在');
        }
        if (!$order_config["notify_config"]&&!$order_config["title"]||!$order_config["table_name"]||!$order_config["order_sn_filed"]||!$order_config["order_money_filed"]||!$order_config["order_status_filed"]||!$order_config["pay_status_filed"]||!$order_config["pay_type_filed"]) {
            return ApiReturn::r(0, [], '请完善订单配置');
        }
        $table_name = Db::name("free_table")->where("aid", $order_config["table_name"])->value("table_name");

        $order_sn_filed = Db::name("free_field")->where("field_id", $order_config["order_sn_filed"])->value("field");
        $order_money_filed = Db::name("free_field")->where("field_id", $order_config["order_money_filed"])->value("field");
        $order_status_filed = Db::name("free_field")->where("field_id", $order_config["order_status_filed"])->value("field");
        $pay_status_filed = Db::name("free_field")->where("field_id", $order_config["pay_status_filed"])->value("field");
        $pay_type_filed = Db::name("free_field")->where("field_id", $order_config["pay_type_filed"])->value("field");

        $order = Db::table($table_name)->where($order_sn_filed, $data['order_sn'])->find();

        if (!$order) {
            return ApiReturn::r(0, [], '订单不存在');
        }
        if ($order[$pay_status_filed] > 0) {
            return ApiReturn::r(0, [], '该订单支付状态已发生改变');
        }

        // if ($order['pay_type'] =='alipay') {
        //     return ApiReturn::r(0, [], '请使用发起支付宝支付接口');
        // }

        // if ($order['pay_type'] =='appleiap') {
        //     return ApiReturn::r(0, [], '请使用发起苹果支付接口');
        // }


        $payment = [
            'order_sn' => $order[$order_sn_filed],
            'amount' => $order[$order_money_filed],
            'transaction_no' => $order[$order_sn_filed],
            'status' => 0,
            'create_time' => time()
        ];
        // Db::name('payment_log')->insertGetId($payment);
        // $order_config["title"]
        $domain = Request::domain();
        $data_pay = array(
            'body' => "在线支付",
            'total_fee' => $order[$order_money_filed],
            'out_trade_no' => $order[$order_sn_filed],
            'notify_url' => $domain.'/index/member_pay/wechat_notify?order_config_id='. $order_config_id."&wxpaytype=".$data['wxpaytype']."&member_id=".$user["member_id"]
        );
        // "http://yufabu.ttk.cc/api/m924/".$order_config["notify_config"]
        Db::startTrans();
        try {
            switch ($data['wxpaytype']) {
                case 'MiniPay' :
                    $data_pay['xcx_openid'] = Db::name('user_info')->where('user_id', $order['user_id'])->value('xcx_openid');
                    if (!$data_pay['xcx_openid']) {
                        exception('获取xcx_openid失败');
                    }
                    $arr = addons_action('WeChat', 'MiniPay', 'pay', [$data_pay], $pay_config);
                    break;
                case 'CodePay':
                    $data_pay['wx_openid'] = Db::name('user_info')->where('user_id', $order['user_id'])->value('wx_openid');
                    if (!$data_pay['wx_openid']) {
                        exception('获取wx_openid失败');
                    }
                    $arr = addons_action('WeChat', 'CodePay', 'pay', [$data_pay], $pay_config);
                    break;
                case 'AppPay':
                    $arr = addons_action('WeChat', 'AppPay', 'pay', [$data_pay], $pay_config);
                    break;
                default:
                    exception('支付方式参数错误');
                    break;
            }
            Db::commit();
        } catch (\Exception $e) {
            Db::rollback();
            return ApiReturn::r(0, [], '调取支付失败' . $e->getMessage());
        }

        if ($arr['result_code'] == 'FAIL') {
            return ApiReturn::r(0, [], $arr ? $arr['err_code_des'] : '调取支付失败');
        }

        return ApiReturn::r(1, $arr, '请按照此配置调起支付');
    }


    /**
    * 获取支付宝预支付订单
    * @param $data
    * @return mixed
    * @author 刘明美 [ liumingmei@zhongbenjituan.com ]
    */
    public function get_alipay($data) {
        //处理平台自己的订单
        $order_config_id = $data["order_config_id"];
        $order_config = Db::name("order_config")->where(["aid" => $order_config_id, "status" => 1])->find();
        // p($order_config);
        $pay_config = Db::name("pay_config")->where("name", 1)->value("config");
        if (!$pay_config) {
            return ApiReturn::r(0, [], '微信支付配置不完善');
        } else {
            $pay_config = json_decode($pay_config, true);
        }
        if (!$order_config) {
            return ApiReturn::r(0, [], '订单配置不存在');
        }
        if (!$order_config["notify_config"]&&!$order_config["title"]||!$order_config["table_name"]||!$order_config["order_sn_filed"]||!$order_config["order_money_filed"]||!$order_config["order_status_filed"]||!$order_config["pay_status_filed"]||!$order_config["pay_type_filed"]) {
            return ApiReturn::r(0, [], '请完善订单配置');
        }
        $table_name = Db::name("free_table")->where("aid", $order_config["table_name"])->value("table_name");

        $order_sn_filed = Db::name("free_field")->where("field_id", $order_config["order_sn_filed"])->value("field");
        $order_money_filed = Db::name("free_field")->where("field_id", $order_config["order_money_filed"])->value("field");
        $order_status_filed = Db::name("free_field")->where("field_id", $order_config["order_status_filed"])->value("field");
        $pay_status_filed = Db::name("free_field")->where("field_id", $order_config["pay_status_filed"])->value("field");
        $pay_type_filed = Db::name("free_field")->where("field_id", $order_config["pay_type_filed"])->value("field");

        $order = Db::table($table_name)->where($order_sn_filed, $data['order_sn'])->find();

        if (!$order) {
            return ApiReturn::r(0, [], '订单不存在');
        }
        if ($order[$pay_status_filed] > 0) {
            return ApiReturn::r(0, [], '该订单支付状态已发生改变');
        }
        $domain = Request::domain();
        $data = array(
            'subject' => $order_config["title"],
            'body' => $order_config["title"],
            'out_trade_no' => $order['order_sn'],
            'total_amount' => $order['payable_money'],
            'notify_url' => $domain.'/index/member_pay/ali_notify?order_config_id='. $order_config_id,
        );
        $pay_config["return_url"] = $order_config["return_url"];
        $pay_config["notify_url"] = $domain.'/index/member_pay/ali_notify?order_config_id='. $order_config_id;
        $pay_config["app_notify_url"] = $domain.'/index/member_pay/ali_notify?order_config_id='. $order_config_id;
        try {
            $string = addons_action('Alipay', 'Aop', 'AlipayTradeAppPayRequest', [$data], $pay_config);
        } catch (\Exception $e) {
            return ApiReturn::r(0, [], '调取支付失败' . $e->getMessage());
        }

        if ($string) {
            return ApiReturn::r(1, $string, '请按照此配置调起支付');
        }
        return ApiReturn::r(0, [], '调取支付失败');
    }
    /**
    * 支付宝异步回调
    * @author ljj
    * @created 2022/7/29
    */
    public function ali_notify() {
        $order_config_id = 13;

        $notify_config = $this->get_order($order_config_id);
        $pay_config = Db::name("pay_config")->where("name", 1)->value("config");

        $pay_config = json_decode($pay_config, true);
        $alipay = addons_action('Alipay', 'Aop', 'init', [], $pay_config);
        if (!$pay_config) {
            $alipay->NotifyProcess(false, "");
        }
        try {
            $arr = $alipay->verifyNotify();
            $hashinfo = explode("/", $notify_config);
            $apiinfo = ApiLists::get(['hash' => $hashinfo[1]]);
            $controller = $apiinfo['apiName'];
            $action = explode("/", $controller);
            if (count($action) > 2) {
                $controller_str = 'controller\\'.$hashinfo[0]."\\".$action[0]."\\".ucfirst($action[1]);
                $action_str = $action[2];
            } else {
                $controller_str = 'controller\\'.$hashinfo[0]."\\".ucfirst($action[0]);
                $action_str = $action[1];
            }
            $arr["pay_type"] = "alipay";
            $txt_path = 'order_verify.txt';

            file_put_contents($txt_path, '支付回调进来了'.$controller_str.PHP_EOL, FILE_APPEND);

            $res = api_action2("\\app", $controller_str, $action_str, [$arr, []]);
            // halt($res);
        } catch (\Exception $e) {
            $alipay->NotifyProcess(false, $e->getMessage());
        }
        $alipay->NotifyProcess(true);
    }

    /**
    * 微信支付异步回调
    * @author ljj
    * @created 2022/7/29
    */
    public function wechat_notify() {
        $order_config_id = 13;

        $notify_config = $this->get_order($order_config_id);
        if (!$notify_config) {
            return "<xml><return_code><![CDATA[FAIL]]></return_code><return_msg><![CDATA[OK3]]></return_msg></xml>";
        }

        $pay_config = Db::name("pay_config")->where("name", 0)->value("config");
        if (!$pay_config) {
            return "<xml><return_code><![CDATA[FAIL]]></return_code><return_msg><![CDATA[OK2]]></return_msg></xml>";
        }
        $pay_config = json_decode($pay_config, true);
        // halt($pay_config);
        // try {
        //     $weChat = addons_action('WeChat', "AppPay", 'initWechatPay',[], $pay_config );

        //     $arr = $weChat->getNotify();

        $hashinfo = explode("/", $notify_config);
        $apiinfo = ApiLists::get(['hash' => $hashinfo[1]]);


        $controller = $apiinfo['apiName'];
        $action = explode("/", $controller);
        if (count($action) > 2) {
            $controller_str = 'controller\\'.$hashinfo[0]."\\".$action[0]."\\".ucfirst($action[1]);
            $action_str = $action[2];
        } else {
            $controller_str = 'controller\\'.$hashinfo[0]."\\".ucfirst($action[0]);
            $action_str = $action[1];
        }
        $arr["pay_type"] = "wechat";

        $res = api_action2("\\app", $controller_str, $action_str, [$arr, []]);
        halt($res);
        // } catch (\Exception $e) {
        //     return "<xml><return_code><![CDATA[FAIL]]></return_code><return_msg><![CDATA[". $e->getMessage()."]]></return_msg></xml>";
        // }
        return "<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>";
    }
    /**
    * 根据id获取订单配置
    */
    private function get_order($order_config_id) {
        $order_config = Db::name("order_config")->where(["aid" => $order_config_id, "status" => 1])->find();
        if (!$order_config) {
            return false;
        }


        return $order_config["notify_config"];
    }

    public function get_one_pay($data, $user) {
        $type = substr($data['order_sn'], 0, 1);
        if ($type == "S") {
            $orderinfo = Db::name("furniture_repair")->where("order_sn", $data['order_sn'])->find();
            $order = [];
            if ($orderinfo) {
                $order["status"] = 0;
                $order['pay_status'] = $orderinfo["pay_status"];
                $order['real_money'] = $orderinfo["price"];
                $order['payable_money'] = $orderinfo["price"];
                $order['order_type'] = 15;

            }
        } else {
            $order = Db::name("order")->where("order_sn", $data['order_sn'])->find();
        }

        /*Db::startTrans();
        try{
            $params = ['order_sn' => $data['order_sn'], 'user' => $user];
            $CommissionFreeze = new \app\automatic\model\m3857\CommissionFreeze();
            $res = $CommissionFreeze->run($params);
            Db::commit();
        } catch (\Exception $e){
            Db::rollback();
            return ApiReturn::r(0, [], $e->getMessage());
        }*/
        // echo 123;die;
        if (!$order) {
            return ApiReturn::r(0, '', lang('订单不存在'));
        }

        if ($order["status"] > 0 || $order['pay_status'] >= 1) {
            return ApiReturn::r(0, [], '该订单支付状态已发生改变');
        }

        if ($order['pay_status'] == 1) {
            return ApiReturn::r(0, '', '订单已支付，请勿重复支付');
        }
        $user_info = Db::name("user")->where('id', $user['id'])->field('id,pay_password,score,vip_last_time')->find();
        // $user_info =  Db::name('user_assets')->where('user_id', $user['id'])->find();
        $user_money = Db::name('user_assets')->where('user_id', $user['id'])->value("user_money");
        $user_info["user_money"] = $user_money;
        // return ApiReturn::r(0, [], '支付密码错误！'.$data["pay_password"]);
        //指纹支付不校验支付密码
        $type = $data['type']??0;
        if ($type == 0) {
            //判断支付密码 是否存在
            if (!$user_info['pay_password']) {
                return ApiReturn::r(-2, [], lang('未设置支付密码').$user_info['pay_password']);
            }

            if (!Hash::check((string)$data['pay_password'], $user_info['pay_password'])) {
                return ApiReturn::r(0, [], '支付密码错误！');
            }

        }
        if ($user_info['user_money'] < $order['payable_money']) {
            // return ApiReturn::r(-1, '', lang('积分不足'));
        }


        Db::startTrans();
        try {
            $transaction_no = date('YmdHis').rand(1000, 9999);
            $remark = lang('支付购买');
            // 记录日志
            \app\automatic\model\m3857\MoneyLog::changeMoney($user['id'], $user_info['user_money'], -$order['payable_money'], 2, $remark, $data['order_sn']);
            if ($order['order_type'] == 15) {
                //商户流程
                $upOrder = [
                    'pay_status' => 1,
                    'pay_type' => 'balance',
                    'pay_time' => time(),
                    "order_status" => $orderinfo["onsite_repair"] == 1?3:2

                ];
                // $upOrder['real_money'] = $order['payable_money'];
                // $upOrder['status'] = 2;
                $res = Db::name("furniture_repair")->where('order_sn', $data["order_sn"])->where("order_status", "=", 1)->update($upOrder);
                if (!$res) {
                    exception(lang('订单处理异常'));
                }
            } else {
                //商户流程
                $upOrder = [
                    'pay_status' => 1,
                    'pay_type' => 'balance',
                    'pay_time' => time(),

                ];
                $upOrder['real_money'] = $order['payable_money'];
                $upOrder['status'] = 1;
                $res = Db::name("order")->where('order_sn', $data["order_sn"])->where("status", "in", [-2, 0])->update($upOrder);
                if (!$res) {
                    exception(lang('订单处理异常'));
                }
                $order_type = $order['order_type'];
                switch ($order_type) {
                    case 3:
                        $res1 = Db::name("order_goods_list")->where(['order_sn' => $data["order_sn"], 'order_status' => 0])->update(['order_status' => 1]);

                        if (!$res1) {
                            exception(lang('订单处理异常'));
                        }
                        $user = Db::name('user')->get($order['user_id']);
                        $params = ['order_sn' => $data['order_sn'],'user' => $user];
                        $CommissionFreeze = new \app\automatic\model\m3857\CommissionFreeze();
                        $res = $CommissionFreeze->run($params);
                        break;
                    case 4:
                        \app\automatic\model\m3857\Integral::verify($order, $user);
                        break;
                    case 5:
                        $res1 = Db::name("order_goods_list")->where(['order_sn' => $data["order_sn"], 'order_status' => 0])->update(['order_status' => 1]);
                        \app\automatic\model\m3857\Goodsactivitygroup::verify($order, $user);
                        break;
                    case 6:
                        $res1 = Db::name("order_goods_list")->where(['order_sn' => $data["order_sn"], 'order_status' => 0])->update(['order_status' => 1]);
                        break;
                    case 7:
                    case 8:
                        self::presaleVerify($order, $user);
                        break;
                    //开通会员订单
                    case 16:
                        
                        $level_order = Db::name('user_level_card_data')->where(['order_sn'=>$data['order_sn'], 'status' => 1])->find();
                        
                        //判断用户是否是续费
                        $vip_time = $level_order['days']*86400;//期限
                        if ($user_info['vip_last_time'] > time()) {
                            $vip_last_time = $user_info['vip_last_time'] + $vip_time;
                        } else {
                            $vip_last_time = time() + $vip_time;
                        }
                        $res = Db::name('user_level_card_data')->where(['user_id'=>$user['id'], 'order_sn'=>$data['order_sn']])->update(['is_pay'=>1,'pay_type'=>'balance','user_vip_last_time'=>$vip_last_time,'update_time'=>time()]);
                        if (!$res) {
                            exception(lang('会员卡订单处理异常'));
                        }
                        
                        $level = Db::name('user_level_card')->where('aid',$level_order['userlevelcard_id'])->value('level')?:1;
                        $res1 = Db::name('user')->where('id',$user['id'])->update(['vip_last_time'=>$vip_last_time,'vip'=>$level,'update_time'=>time()]);
                        if (!$res1) {
                            exception(lang('会员卡订单处理异常2'));
                        }

                        break;
                    default:
                        // $res1 = Db::name("order_goods_list")->where(['order_sn' => $data["order_sn"], 'order_status' => 0])->update(['order_status' => 1]);
                        break;

                }

                /*        if (in_array($order['order_type'], [3])) {
                    $res1 = Db::name("order_goods_list")->where(['order_sn' => $data["order_sn"], 'order_status' => 0])->update(['order_status' => 1]);

                    if (!$res1) {
                        exception(lang('订单处理异常'));
                    }
                    $params = ['order_sn' => $data['order_sn'],'user' => $user];
                    $CommissionFreeze = new \app\automatic\model\m3857\CommissionFreeze();
                    $res = $CommissionFreeze->run($params);
                }

                if ($order['order_type'] == 4) {
                    \app\automatic\model\m3857\Integral::verify($order, $user);
                }

                if (in_array($order['order_type'], [5])) {
                     $res1 = Db::name("order_goods_list")->where(['order_sn' => $data["order_sn"], 'order_status' => 0])->update(['order_status' => 1]);

                    \app\automatic\model\m3857\Goodsactivitygroup::verify($order, $user);
                }*/

            }

            Db::commit();
        } catch (\Exception $e) {
            Db::rollback();
            return ApiReturn::r(0, [], $e->getMessage());
        }
        return ApiReturn::r(1, [], lang('支付成功'));
        // if ($order["status"]==0 || $order["pay_status"]==0) {
        //     //商户流程
        //     \app\automatic\model\m3857\Order::verify($order["order_sn"], 'balance', '', $order["order_money"]);
        //     return ApiReturn::r(1, $order, lang('下单成功，系统已自动支付'));
        // }

    }
    /**
    * 线下支付
    **/
    public function bank_pay($data, $user) {
        //处理平台自己的订单

        $order = Db::name("order")->where(['order_sn' => $data['order_sn']])->find();

        if (!$order) {
            return ApiReturn::r(0, '', lang('订单不存在'));
        }
        if ($order['pay_status'] == 1) {
            return ApiReturn::r(0, '', '订单已支付，请勿重复支付');
        }

        switch ($order['order_type']) {
            case 1:
                $remark = lang('现金充值订单');
                if ($order['product_id']) {
                    $money = Db::name("user_recharge_rule")->where('id', $order['product_id'])->value('add_money');
                } else {
                    $money = $order['order_money'];
                }

                $after_money = \app\automatic\model\m3857\MoneyLog::changeMoney($user['id'], $user['user_money'], $money, 1, $remark, $order_sn);
                if (!$after_money) {
                    exception(lang('订单处理异常'));
                }
                break;
            case 2:
                $remark = lang('虚拟币充值订单');
                if ($order['product_id']) {
                    $money = Db::name("user_recharge_rule")->where('id', $order['product_id'])->value('add_money');
                } else {
                    $money = $order['order_money'];
                }

                $after_money = \app\userbase\model\VirtualMoneyLog::changeMoney($user['id'], $user['user_virtual_money'], $money, 1, $remark, $order_sn);
                if (!$after_money) {
                    exception(lang('订单处理异常'));
                }
                break;
            case 3:
            case 6:
                //商城订单
                $upOrder = [
                    'pay_status' => 1,
                    'pay_type' => "bank",
                    'pay_time' => time(),
                    'bank_pay_info' => json_encode($data)
                ];
                $upOrder['status'] = 1;

                $res = Db::name("order")->where('order_sn', $order["order_sn"])->where("status", "in", [-2, 0])->update($upOrder);
                Db::name("order_goods_list")->where('order_sn', $order["order_sn"])->update(["order_status" => 1]);

                if (in_array($order['order_type'], [3])) {
                    $params = ['order_sn' => $data['order_sn'],'user' => $user];
                    $CommissionFreeze = new \app\automatic\model\m3857\CommissionFreeze();
                    $res = $CommissionFreeze->run($params);
                }
                if (in_array($order['order_type'], [5])) {
                    \app\automatic\model\m3857\Goodsactivitygroup::verify($order, $user);
                }
                break;
            case 5:
                \app\automatic\model\m3857\Goodsactivitygroup::verify($order, $user);

                $upOrder = [
                    'pay_status' => 1,
                    'pay_type' => "bank",
                    'pay_time' => time(),
                    'bank_pay_info' => json_encode($data)
                ];
                $upOrder['status'] = 1;

                $res = Db::name("order")->where('order_sn', $order["order_sn"])->where("status", "in", [-2, 0])->update($upOrder);
                Db::name("order_goods_list")->where('order_sn', $order["order_sn"])->update(["order_status" => 1]);

            case 7:
            case 8:
                self::presaleVerify($order, $user);
                break;


            default:
                break;
        }



        return ApiReturn::r(1, [], lang('支付成功'));
    }


    /**
    * 订单回调
    * @param Order $order
    * @param User $user
    * @author 晓风<215628355@qq.com>
    */
    public static function presaleVerify($order, $user) {
        $orderSn = $order["order_sn"];
        $orderType = $order['order_type'];
        $goods_thumb = \app\automatic\model\m3857\OrderGoods::where('order_sn', $orderSn)->value("goods_thumb");
        $status = in_array($orderType, [7]) ? 7 : 1;
        if ($order['send_type'] == 1 && $status == 1) {
            $status = 2;
        }

        if ($orderType == 8) {
            //预售订单支付尾款
            if ($order['send_type'] == 1) {
                $status = 2;
            }

            $preOrder = \app\automatic\model\m3857\Order::where(['order_type' => 7, 'advance_sn' => $order["advance_sn"], 'status' => 7])->find();
            \app\automatic\model\m3857\Order::where(['order_type' => 7, 'advance_sn' => $order["advance_sn"], 'status' => 7])->update(['status' => $status]);

            $orderSn = $preOrder["order_sn"];
            $content = "尾款已支付成功";
            \app\automatic\model\m3857\OrderGoods::where(['order_sn' => $orderSn, 'order_status' => 7])
            ->setField(['order_status' => $status]);
            $balanceOrder = \app\automatic\model\m3857\Order::where(['order_type' => 7, 'advance_sn' => $order["advance_sn"]])->find();
            $balanceOrderSn = $balanceOrder["order_sn"];
            $goods_thumb = \app\automatic\model\m3857\OrderGoods::where('order_sn', $balanceOrderSn)->value("goods_thumb");


        } else {
            $content = $orderType == 7 ? "预付款已支付成功" : '已支付成功';
            Db::name("order_goods_list")->where(['order_sn' => $orderSn, 'order_status' => 0])
            ->update(['order_status' => $status]);
        }

        \app\automatic\model\m3857\Operationsuggestions::create([
            "to_user_id" => $order['user_id'],
            "title" => '您的订单支付成功',
            "order_sn" => $orderSn,
            "content" => "您的订单：{$orderSn}, {$content}" . ($order["status"] == -2 ? '，系统已自动撤销取消状态' : ''),
            "msg_type" => 2,
            "thumb" => $goods_thumb,
            "custom" => json_encode(['type' => 'order', 'id' => $orderSn])
        ]);
        \app\automatic\model\m3857\OrderAction::addLog($orderSn, "订单支付成功", 1, $order["user_id"]);
        return true;
    }

}